package com.tm.servicemsm.controller;

import com.tm.servicemsm.demos.LoanApplication;
import com.tm.servicemsm.demos.LoanPurposeDTO;

import java.math.BigDecimal;

/**
 * 2024/7/22 借款审核的服务类 Cjj
 */
public class LoanApprovalService {
    public void approveLoan(LoanApplication loanApplication){
        //假设的审核逻辑
        if(loanApplication.getPurposeDTO().getPurpose().isEmpty()){
            throw new IllegalArgumentException("借款用途不能为空");
        }
        if(loanApplication.getAmount().compareTo(new BigDecimal("10000"))<0){
            throw new IllegalArgumentException("贷款额度不能低于10000");
        }

        //假设的审核通过后的操作
        System.out.println("借款申请通过审核,用户ID:"+loanApplication.getUserId());
    }

    //使用示列
    public class LoanApprovalExample{
        public static void main(String[] args) {
            LoanApplication loanApplication = new LoanApplication();
            loanApplication.setUserId("user123");
            loanApplication.setAmount(new BigDecimal("15000"));

            LoanPurposeDTO purposeDTO = new LoanPurposeDTO();
            purposeDTO.setPurpose("家庭紧急救援");
            loanApplication.setPurposeDTO(purposeDTO);

            LoanApprovalService loanApprovalService = new LoanApprovalService();
            try {
                loanApprovalService.approveLoan(loanApplication);
            }catch (IllegalArgumentException e){
                System.out.println("借款申请未通过审核："+e.getMessage());
            }


        }
    }
}
